<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>Login</title>
    <%= stylesheet_link_tag "../javascripts/ext/resources/css/ext-all.css" %>
    <%= stylesheet_link_tag "/stylesheets/blue.css" %>
    <%= javascript_include_tag "/javascripts/ext/adapter/prototype/prototype.js" %>
    <%= javascript_include_tag "/javascripts/ext/adapter/prototype/scriptaculous.js" %>
    <%= javascript_include_tag "/javascripts/ext/adapter/prototype/effects.js" %>
    <%= javascript_include_tag "/javascripts/ext/adapter/prototype/ext-prototype-adapter.js" %>
    <%if session[:explorer_info]=="IE" %>
      <%= javascript_include_tag "/javascripts/ext/adapter/ext/ext-base.js" %>
    <%end %>
    <%= javascript_include_tag "/javascripts/ext/ext-all.js" %>
    <%= javascript_include_tag "/javascripts/ext/build/locale/ext-lang-zh_CN.js" %>
  </head>
  <body>
    <script>
        Ext.onReady(function(){
            Ext.QuickTips.init();
            // turn on validation errors beside the field globally
            Ext.form.Field.prototype.msgTarget = 'side';
            //var bd = Ext.getBody();
            var loginButton = new Ext.Button({
                text: '    登  录    ',
                handler: function(){
                    loginButton.setDisabled(true);
                    if (loginForm.form.isValid()) {
                        loginForm.form.submit({
                            url: '/index/person_login',
                            method: 'GET',
                            success: function(result, resp){
                                if (resp.result.info.indexOf("成功") >= 0) {
                                    window.document.location.href = '/index/happy_person';
                                }
                                else {
                                    Ext.MessageBox.alert('消息', resp.result.info);
                                    loginButton.setDisabled(false);
                                }
                            },
                            failure: function(result, request){
                                loginButton.setDisabled(false);
                                Ext.MessageBox.alert('消息', '登录过程中和服务器的通信失败!');
                            }
                        });
                    }
                    else {
                        loginButton.setDisabled(false);
                        Ext.MessageBox.alert('输入验证有错', '请输入必输选项');
                    }
                }
            })
            var logoPanel = new Ext.Panel({
                baseCls: 'x-plain',
                bodyStyle: 'background:#f9f9f9 url(/images/system/a380.jpg) no-repeat center center;',
                region: 'center'
            });
            var loginForm = new Ext.FormPanel({
                //labelAlign: 'top',
                baseCls: 'x-plain',
                labelWidth: 100, // label settings here cascade unless overridden
                url: '/index/person_login',
                frame: false,
                //title: '系统登录',
                //bodyStyle: 'padding:5px 5px 0',
                bodyStyle: 'background:#f9f9f9 none; color:#222; padding:5px 35px;',
                height: 70,
                width: 200,
                defaults: {
                    width: 200
                },
                defaultType: 'textfield',
                region: 'south',
                items: [{
                        fieldLabel: '用户名',
                        name: 'user_name',
                        allowBlank: false
                    }, {
                        fieldLabel: '密码',
                        name: 'password',
                        inputType: 'password',
                        allowBlank: false
                    }]//,

                //buttons: [loginButton]
            });
            //loginForm.render(document.body);
            //loginForm.getEl().center();
            var dialog = new Ext.Window({
                buttons: [loginButton],
                buttonAlign: 'right',
                closable: false,
                draggable: true,
                height: 320,
                id: 'login-win',
                layout: 'border',
                minHeight: 320,
                minWidth: 430,
                plain: false,
                resizable: true,
                items: [
                    logoPanel,
                    loginForm
                ],
                title: '个人订票系统',
                width: 430
            });
            dialog.show();
        });
    </script>
  </body>
</html>
